package com.lottery.material.service.portal.user.impl;

import com.lottery.material.dao.article.ArticleActiveInfoMapper;
import com.lottery.material.dao.article.ArticleInfoMapper;
import com.lottery.material.dao.portaluser.DeleteArticleRecordMapper;
import com.lottery.material.pojo.article.ArticleInfo;
import com.lottery.material.pojo.portaluser.DeleteArticleRecord;
import com.lottery.material.service.portal.user.DeleteArticleRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * Description:    删除文章服务实现类
 * Author:         sunny
 * CreateDate:     2019-04-29 17:32
 */
@Service
public class DeleteArticleRecordServiceImpl implements DeleteArticleRecordService {

    @Autowired
    private DeleteArticleRecordMapper deleteArticleRecordMapper;
    @Autowired
    private ArticleInfoMapper articleInfoMapper;
    @Autowired
    private ArticleActiveInfoMapper articleActiveInfoMapper;

    /**
     * description: 保存文章删除记录
     * author sunny
     * createDate 2019-04-29 下午 5:36
     *
     * @param deleteArticleRecord
     * @return
     */
    @Override
    public Integer saveArticleRecord(DeleteArticleRecord deleteArticleRecord) {
        ArticleInfo articleInfo = articleInfoMapper.findByArticleId(deleteArticleRecord.getArticleId());
        if (Objects.isNull(articleInfo)) {
            return -1;
        }

        Integer count = deleteArticleRecordMapper.insertSelective(deleteArticleRecord);
        if (count > 0) {
            articleInfoMapper.deleteByArticleId(articleInfo.getArticleId());
            articleActiveInfoMapper.deleteByArticleId(articleInfo.getArticleId());
            return count;
        } else {
            return -1;
        }
    }
}
